package com.define.ssh.util;

import java.util.HashMap;
import java.util.List;

import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

import com.define.ssh.dao.InterfaceIpDao;
import com.define.ssh.model.InterfaceIp;
import com.sxit.ecwx.core.utils.EcwxUtils;

public class InterfaceIpData {
	private static InterfaceIpData instance = null;   
	public  static int compid=5;
    private HashMap<String, List<InterfaceIp>> CommonMap = null;  
    private static HashMap<String,String> TableMap =new HashMap<String,String>();
    static{
    	TableMap.put("user","user");	
    	TableMap.put("compdept","compdept");
    	TableMap.put("deptuser","deptuser");
    	TableMap.put("groupinfo_regular","groupinfo_regular");
    	TableMap.put("groupmember_regular","groupmember_regular");
    	TableMap.put("m_warn_level","m_warn_level");
    	TableMap.put("m_warn_member","m_warn_member");
    	TableMap.put("m_warn_scope","m_warn_scope");
    	TableMap.put("m_warn_target","m_warn_target");
    	TableMap.put("tb_fictitious_team","tb_fictitious_team");
    	TableMap.put("tb_fictitious_user","tb_fictitious_user");
    	try{
    		compid=Integer.parseInt(EcwxUtils.readPropertiesValue("compid", "ecwxConfig.properties"));
    		System.out.println("企业id为========================="+compid);
		}catch(Exception e)
		{
		  e.printStackTrace();	
		}
    }
    
    private InterfaceIpData() {  
    	WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
		InterfaceIpDao interfaceIpDao=(InterfaceIpDao) wac.getBean("interfaceIpDao");
		CommonMap=interfaceIpDao.appData();
    }  
    private static synchronized void syncInit() {  
      if (instance == null) {  
        instance = new InterfaceIpData();  
      }  
    }  
    public static InterfaceIpData getInstance() {  
      if (instance == null) {  
        syncInit();  
      }  
      return instance;  
    }
	
	public HashMap<String, List<InterfaceIp>> getCommonMap() {
		return CommonMap;
	}
	public void setCommonMap(HashMap<String, List<InterfaceIp>> commonMap) {
		CommonMap = commonMap;
	}
	public static void setInstance(InterfaceIpData instance) {
		InterfaceIpData.instance = instance;
	}
}
